<!--
 * @Author: wankong
 * @Date: 2021-10-07 16:18:01
 * @LastEditTime: 2021-10-19 19:03:28
-->
<template>
  <el-container class="pages">
    <el-header
      ><el-row type="flex" justify="space-between" style="align-item: center">
        <el-col :span="6"
          ><h1 style="color: #fff">{{ webtitle }}</h1></el-col
        >
        <el-col :span="3">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userinfo">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-header>
    <el-container class="pages">
      <el-aside :width="menuCollapse ? '70px' : '190px'"
        ><el-menu
          :default-active="nowactive"
          class="el-menu-vertical-demo"
          :collapse="menuCollapse"
          :router="true"
          unique-opened
          :collapse-transition="true"
          @select="changeActive"
        >
          <div class="Collapse" @click="openCallapse">
            {{ menuCollapse ? " &lt;&gt;" : " &gt;&lt;" }}
          </div>
          <el-menu-item index="1" route="/home/welcome">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="2" route="/home/editor">
            <i class="el-icon-edit-outline"></i>
            <span slot="title">写文章</span>
          </el-menu-item>
          <el-menu-item index="3" route="/home/article">
            <i class="el-icon-document"></i>
            <span slot="title">文章</span>
          </el-menu-item>
          <el-menu-item index="4" route="/home/tags">
            <i class="el-icon-collection-tag"></i>
            <span slot="title">标签</span>
          </el-menu-item>
          <el-menu-item index="5" route="/home/cate">
            <i class="el-icon-folder-opened"></i>
            <span slot="title">分类</span>
          </el-menu-item>
          <el-menu-item index="6" route="/home/comment">
            <i class="el-icon-chat-dot-square"></i>
            <span slot="title">评论</span>
          </el-menu-item>
          <el-menu-item index="7" route="/home/links">
            <i class="el-icon-link"></i>
            <span slot="title">友链</span>
          </el-menu-item>
          <el-menu-item index="8" route="/home/setting">
            <i class="el-icon-setting"></i>
            <span slot="title">设置</span>
          </el-menu-item>
          <el-menu-item index="9" route="/home/about">
            <i class="el-icon-help"></i>
            <span slot="title">关于</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <el-card> <router-view></router-view></el-card>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  components: {},
  data() {
    return {
      menuCollapse: false,
      webtitle: "晚空的博客后台",
      username: "晚空",
      nowactive: "1",
    };
  },
  methods: {
    handleCommand(command) {
      if (command === "userinfo") {
        return this.userinfo();
      } else if (command === "logout") {
        return this.logout();
      }
    },
    userinfo() {
      this.$router.push("user");
    },
    logout() {
      this.$message.success("您已退出");
      window.sessionStorage.clear();
      this.$router.push({ name: "Home" });
      return true;
    },
    openCallapse() {
      this.menuCollapse = !this.menuCollapse;
    },
    initCreative() {
      this.nowactive = window.sessionStorage.getItem("isactive")
        ? window.sessionStorage.getItem("isactive") + ""
        : "1";
    },
    changeActive(nowid) {
      window.sessionStorage.setItem("isactive", nowid);
    },
  },
  created() {
    this.initCreative();
  },
};
</script>

<style lang="less" scoped>
.pages {
  min-width: 1366px;
  height: 100%;
}
.el-header {
  background: linear-gradient(to left, #409eff, rgb(134, 168, 231));
}
.el-header,
.el-footer {
  line-height: 60px;
}
.el-menu-vertical-demo {
  overflow: hidden;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 180px;
  min-height: 400px;
}
.el-aside {
  height: 100%;
  transition: width 0.25s;
  overflow: hidden;
}
.Collapse {
  width: 110%;
  text-align: center;
  line-height: 35px;
  background: #409eff;
  color: white;
  cursor: pointer;
}
.Collapse:hover {
  color: white;
}
.el-main {
  padding: 5px;
  min-height: 80vh;
}
.el-card {
  
  min-height: 80vh;
}
</style>